﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using System.ComponentModel;

namespace ContentPipelineExtension.Models
{
    [ContentProcessor(DisplayName = "Model (Custom) - Select Effect File")]
    public class CustomModelEffect : ModelProcessor
    {
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            return base.Process(input, context);
        }

        [Browsable(false)]
        public override MaterialProcessorDefaultEffect DefaultEffect
        {
            get
            {
                return base.DefaultEffect;
            }
            set
            {
                base.DefaultEffect = value;
            }
        }

        [Browsable(true)]
        public string Effect
        {
            get
            {
                return effectName;
            }
            set
            {
                effectName = value;
            }
        }
        private string effectName;


        protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
        {
            EffectMaterialContent myMaterial = new EffectMaterialContent();

            if (!String.IsNullOrWhiteSpace(effectName))
                myMaterial.Effect = new ExternalReference<EffectContent>(effectName);
            else
            {
                throw new ArgumentNullException("Effect File Not Specified!");
            }

            return context.Convert<MaterialContent, MaterialContent>(myMaterial, typeof(MaterialProcessor).Name);
        }

    }
}
